Component({
  properties: {
    thingList: {
      type: Array,
      value: []
    }
  },
  lifetimes: {
    attached() {
      const app = getApp();
      const userId = wx.getStorageSync('userId');
      const token = wx.getStorageSync('token');
      console.log('从本地存储获取的 userId:', userId);
      console.log('从本地存储获取的 token:', token);
      if (userId && token) {
        app.globalData.userId = userId;
        app.globalData.token = token;
        console.log('登录状态已恢复');
      } else {
        console.log('未找到登录信息，登录状态未恢复');
      }
  
      // this.getCollectThingList();
      // this.getWishThingList();
      // this.getUserAvatar();
    }
  },
  methods: {
    navigateToSearch: function() {
      // 触发自定义事件，通知页面进行跳转
      this.triggerEvent('searchTap');
    },
    onItemTap: function(event) {
      const app = getApp();
      const userId = app.globalData.userId;
      const token = app.globalData.token;
      if (!userId || !token) {
        // 未登录，提示用户登录
        wx.showModal({
          title: '提示',
          content: '请先登录',
          success: function (res) {
            if (res.confirm) {
              // 跳转到登录页面
              wx.navigateTo({
                url: '/pages/login/login'
              });
            }
          }
        });
        return;
      }
      const item = event.currentTarget.dataset.item;
      this.triggerEvent('itemTap', { item });
    }
  }
})